﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TheHeGeoCommercial.News
{
    public partial class UcNews : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        protected void LoadData()
        {
            using (var ent = new Dao.TheheGeoCommercialEntities())
            {
                var newsObj = (from n in ent.TinTucs
                               
                               select new
                                      {
                                          n.id,
                                          n.NewsTitle,
                                          n.ShortView,
                                          n.AvatarPath
                                      }).ToList();
                var dt = new DataTable();
                dt.Columns.Add("NewsTitle", typeof (string));
                dt.Columns.Add("ShortView", typeof(string));
                dt.Columns.Add("AvatarPath", typeof(string));
                dt.Columns.Add("DetailUrl", typeof(string));
                foreach (var obj in newsObj){
                    var dr = dt.NewRow();
                    dr["NewsTitle"] = obj.NewsTitle;
                    dr["ShortView"] = obj.ShortView;
                    dr["AvatarPath"] = obj.AvatarPath;
                    dr["DetailUrl"] = "NewsDetail.aspx?id=" + obj.id;
                    dt.Rows.Add(dr);
                    dtNews.DataSource = dt;
                    dtNews.DataBind();
                }
            }
                   
        }
    }
}